<?php
include("auth.php");
require('db.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Add Trash</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>

<?php
require('db.php');
// If form submitted, insert values into the database.
if (isset($_POST['cameraid'])){
    //collect cameraID, lat and long values
    $cameraid = $_POST['cameraid'];
    $latitude = $_POST['latitude'];
    $longitude = $_POST['longitude'];

    //need to FIND the DATETIME using PHP
    $currentDateTime = date('Y-m-d h:m:s');

    $sql = "INSERT INTO rubbishlocation (cameraid, latitude, longitude, time)
                values ('$cameraid','$latitude','$longitude','$currentDateTime')";
    
    if (mysqli_query($con, $sql)) {
        echo "New record created successfully! Sent at datetime '$currentDateTime'";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($con);
    }

}
?>


<div class="form">
<h1>Add trash to database</h1>
<form action="" method="post" name="datasend">
<input type="number" name="cameraid" placeholder="Camear ID" required />
<input type="number" name="latitude" placeholder="Latitude" required />
<input type="number" name="longitude" placeholder="Longitude" required />


<input name="submit" type="submit" value="Submit data" />
</form>
</div>

<p><a href="index.php">Home</a></p>
<a href="logout.php">Logout</a>
</div>
</body>
</html>

